layui.use(function () {
    let form = layui.form;
    let $ = layui.jquery;
    let layer = layui.layer;

    form.verify({
        content: (value, item) => {
            if (value.length > 50) {
                return '评论内容不能超过50个字符';
            }
        },
        is_anonymous: (value, item) => {
            if (value == 0) {
                return '请选择是否匿名';
            }
        }
    });

    form.on('submit(comment)', function (data) {
        let comment = $("#comment-form").serialize();
        $.post('/comment/comment', comment, (result) => {
            if (result.state == 200) {
                layer.msg(result.message, {
                    icon: 1,
                    time: 3000
                });
                $("#comment-form")[0].reset();
            } else {
                layer.msg(result.message, {
                    icon: 2,
                    time: 3000
                });
            }
        });
        return false;
    });
});